<template>
	<view class="box">
		<image src="../../static/logo.png" mode=""></image>
		<view class="" style="margin-bottom: 60rpx;">
			草原宝
		</view>
		<u-input placeholder="请输入手机号" style="width: 600rpx;background-color: #F5F8FF;padding: 20rpx;" border="none"
			v-model="form.account">
			<u-icon name="account-fill" slot="prefix" size="20"></u-icon>
		</u-input>
		<u-input placeholder="请输入密码" style="width: 600rpx;margin-top: 26rpx;background-color: #F5F8FF;padding: 20rpx;"
			border="none" v-model="form.password">
			<u-icon name="lock-fill" slot="prefix" size="20"></u-icon>
		</u-input>
		<view class="" style="text-align: right;width: 90%;margin-top: 30rpx;" @click="toReg">
			没有账号，点击注册
		</view>
		<view class="btn" @click="login">
			登录
		</view>
	</view>
</template>

<script>
	import {
		toLogin
	} from "@/request/api/login.js"
	export default {
		data() {
			return {
				form: {
					"account": "",
					"password": "123456"
				}
			}
		},
		methods: {
			async login() {
				let res = await toLogin(this.form);
				if (res.code == 1) {
					uni.setStorageSync("token", res.data.userinfo.token)
					uni.setStorageSync("userInfo", res.data.userinfo)
					this.$store.commit('user/setData', {
						key: "userInfo",
						value: res.data.userinfo
					})
					this.$store.dispatch('user/timLogin')
					uni.reLaunch({
						url: "/pages/home/home"
					})
				}

			},
			toReg() {
				uni.reLaunch({
					url: "/pages/reg/reg"
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: white;
		height: 100%;
	}
</style>
<style scoped lang="scss">
	.btn {
		background-color: #2DBC26;
		color: white;
		width: 600rpx;
		border-radius: 100px;
		padding: 24rpx;
		margin-top: 50rpx;
		text-align: center;
	}

	.box {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 200rpx 30rpx;

		image {
			width: 200rpx;
			height: 200rpx;
			margin-bottom: 30rpx;
			border-radius: 30rpx;
		}
	}
</style>